
#include <iostream>
#include <set>
#include "spdlog/spdlog.h"
#include "log_service.h"
#include "log_service_impl.h"

int LogService::init(std::initializer_list<LogService::LogType> dests)
{
    std::set<LogService::LogType> types(dests);
    return LogServiceImpl::instance().init(types);
}

int LogService::init(std::initializer_list<std::string> dests)
{
    auto from_str = [](const std::string &type) {
        if (type == "stdout") {
            return LogService::STDOUT_LOG;
        } else if (type == "file") {
            return LogService::FILE_LOG;
        } else if (type == "udp") {
            return LogService::UDP_LOG;
        } else if (type == "color") {
            return LogService::COLOR_LOG;
        }
        return LogService::UNKNOWN_LOG;
    };

    // remove duplicate types
    std::set<LogService::LogType> types;
    for (const auto &type : dests)
    {
        types.insert(from_str(type));
    }
    return LogServiceImpl::instance().init(types);
}

std::shared_ptr<spdlog::logger> LogService::create(const std::string &tag, spdlog::level::level_enum level)
{
    return LogServiceImpl::instance().create(tag, level);
}

std::shared_ptr<spdlog::logger> LogService::create(const std::string &tag, const std::string &level_str)
{
    return LogServiceImpl::instance().create(tag, spdlog::level::from_str(level_str));
}

